package com.wjk.kylin.rpc.core.util;

import java.util.concurrent.*;

/**
 *
 * @author wjk
 */
public class ThreadPoolUtil {

    /**
     * make server thread pool
     *
     * @param serverType
     * @return
     */
    public static ThreadPoolExecutor makeServerThreadPool(final String serverType, int corePoolSize, int maxPoolSize) {
        ThreadPoolExecutor serverHandlerPool = new ThreadPoolExecutor(
                corePoolSize,
                maxPoolSize,
                60L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(99999),
                runnable -> new Thread(runnable, "kylin-rpc-" + serverType + "-serverHandlerPool-" + runnable.hashCode()),
                (runnable, executor) -> {
                    throw new RpcException("kylin-rpc " + serverType + " Thread pool is EXHAUSTED!");
                });
        return serverHandlerPool;
    }

}
